<!--  -->
<template>
  <div class="sefaty">
    <h1>我的密码信息</h1>
    <h2>更改密码</h2>
    <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item style="width: 500px" label="新密码" prop="password">
        <el-input type="password" v-model="ruleForm.password" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item style="width: 500px" label="确认密码" prop="checkPass">
        <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name:"Sefaty",
  data () {
    var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        } else {
          if (this.ruleForm.checkPass !== '') {
            this.$refs.ruleForm.validateField('checkPass');
          }
          callback();
        }
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.ruleForm.password) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
    return {
      ruleForm: {
          password: '',
          checkPass: '',
        },
        rules: {
          password: [
            { validator: validatePass, trigger: 'blur' }
          ],
          checkPass: [
            { validator: validatePass2, trigger: 'blur' }
          ],
          
        }
    };
  },
   methods: {
      submitForm(formName) {
        console.log(formName)
        // this.$refs[formName].validate( async (valid)  => {
        //   if (valid) {
        //     // console.log(this.ruleForm.password)
        //     const {data:res} = await this.$http.post("/dqxmall/userinfo/update",this.ruleForm)
        //     // console.log(res)
        //     if(res.msg === "success"){
        //       this.$message.success("密码修改成功")
        //     }
        //   } else {
        //     return false;
        //   }
        // });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
}

</script>
<style lang='less' scoped>
h1{
    font-weight: 700;
    font-size: 25px;
    text-align: center;
    margin: 20px;
  }
h2{
    font-weight: 700;
    font-size: 20px;
    margin: 20px 50px;
  }
</style>